package com.example.definedialog;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MyDialog {
	private Context mContext;
	private TextView tv_title;
	private TextView tv_message;
	private Button bt_ok;
	private View view;
	private LayoutInflater layoutInflater;
	private Dialog loadingDialog;
	private onClickDialogListener onClickDialogListener1;

	public MyDialog(Context context) {
		this.mContext = context;
		this.layoutInflater = LayoutInflater.from(context);
		onCreateView();
	}

	public void onCreateView() {
		view = layoutInflater.inflate(R.layout.dialog_golbal, null);
		tv_title = (TextView) view.findViewById(R.id.tvTitle1);
		tv_message = (TextView) view.findViewById(R.id.tvMessage1);
		bt_ok = (Button) view.findViewById(R.id.btnOK1);
		loadingDialog = new Dialog(mContext, R.style.mydialog);// 创建自定义样式
		
	}

	public void showDialog() {
		loadingDialog.show();
	}
	
	public void closeDialog(){
		
		loadingDialog.dismiss();
	}

	public void initUI( String title, String messsage, String button) {

		tv_title.setText(title);
		tv_message.setText(messsage);
		bt_ok.setText(button);
		bt_ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
//				onClickDialogListener1.onClickRightButton();
				onClickDialogListener1.onClickButton();
			}
		});
		
//		yes.setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				onClickDialogListener1.onClickLeftButton();
//			}
//		});
		
		loadingDialog.setContentView(view);
	}

	public interface onClickDialogListener{
		
//		public void onClickLeftButton();
//		public void onClickRightButton();
		
		public void onClickButton();
		
	}
	
	public void setOnDialogClickListener(onClickDialogListener onClickDialogListener) {
		this.onClickDialogListener1 = onClickDialogListener;
	}
}
